package leetcode_2501_2600;

import java.util.ArrayList;
import java.util.List;

public class LeeCode_2523 {
    public static void main(String[] args) {

    }
    private static int[] closestPrimes(int left, int right) {
        List<Integer> list = new ArrayList<>();
        for (int i = left; i <= right; i++) {
            if (charge(i)){
                list.add(i);
            }
        }
        if (list.size() < 2)
            return new int[]{-1, -1};
        int min = Integer.MAX_VALUE;
        int[] ans = new int[2];
        for (int i = 0; i < list.size() - 1; i++) {
            int diff = list.get(i + 1) - list.get(i);
            if (diff < min){
                ans[0] = list.get(i);
                ans[1] = list.get(i + 1);
                min = diff;
            }
        }
        return ans;
    }
    private static boolean charge(int x){
        if (x == 1)
            return false;
        int i = 2;
        while (i * i <= x){
            if (x % i == 0)
                return false;
            i++;
        }
        return true;
    }
}
